//
//  ZNGRequestTool.h
//  开店通
//
//  Created by 张浩 on 15/9/29.
//  Copyright © 2015年 张浩. All rights reserved.
//

#import "AFHTTPSessionManager.h"


typedef NS_ENUM(NSInteger, HTTPMethod){
    HTTPMethodGET,
    HTTPMethodPOST
};

@interface ZNGBaseRequestResult : NSObject
@property(nonatomic, copy)NSString *message;
@property(nonatomic, assign)NSInteger code;
@property(nonatomic, copy)NSString *status;
@end


typedef void (^CustomSuccessAction)(ZNGBaseRequestResult *result, BOOL needShowMessage);
typedef BOOL (^MessageShowRuleBlock)(NSString *url, NSDictionary *param);

@interface ZNGRequestTool : NSObject

+ (void)setSuccessAction:(CustomSuccessAction)successAction;

+ (void)setMessageShowRule:(MessageShowRuleBlock)ruleBlock;

+ (void)get:(NSString *)url param:(id)param successBlock:(void (^)(ZNGBaseRequestResult *result))success failure:(void (^)(NSError *error))failure;

+ (void)post:(NSString *)url param:(id)param successBlock:(void (^)(ZNGBaseRequestResult *result))success failure:(void (^)(NSError *error))failure;

+ (void)get:(NSString *)url param:(id)param resultClass:(Class)resultClass successBlock:(void (^)(id result))success failure:(void (^)(NSError *error))failure;

+ (void)post:(NSString *)url param:(id)param resultClass:(Class)resultClass successBlock:(void (^)(id result))success failure:(void (^)(NSError *error))failure;

+ (void)post:(NSString *)url param:(id)param constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))formData successBlock:(void (^)(ZNGBaseRequestResult *result))success failure:(void (^)(NSError *error))failure;

+ (void)get:(NSString *)url param:(id)param constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))formData successBlock:(void (^)(ZNGBaseRequestResult *result))success failure:(void (^)(NSError *error))failure;

+ (void)post:(NSString *)url param:(id)param resultClass:(Class)resultClass constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))formData successBlock:(void (^)(id result))success failure:(void (^)(NSError *error))failure;

+ (void)get:(NSString *)url param:(id)param resultClass:(Class)resultClass constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))formData successBlock:(void (^)(id result))success failure:(void (^)(NSError *error))failure;
@end


typedef void (^SetHttpHeaderField)(AFHTTPSessionManager *manager);

@interface ZNGRequestManager : AFHTTPSessionManager
+ (void)setHeaderField:(SetHttpHeaderField)setHeader;
+ (instancetype)shareManager;
@end